﻿using SRB.Tg.Operate;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using Teigha.Colors;
using Teigha.DatabaseServices;
using Teigha.Geometry;

namespace SRB.Tg.DrawingStandard
{
    public class InitConfig
    {
        static System.Data.DataTable dtProjectConfig = new System.Data.DataTable();
        public static void InitStandardConfig()
        {
            InitLayer();
            string font = "仿宋_GB2312";
            if (!string.IsNullOrWhiteSpace(IniOper.getInstance().Font))
                font = IniOper.getInstance().Font;
            double fontWidth = 0.75;
            if (!string.IsNullOrWhiteSpace(IniOper.getInstance().FontWidth))
                fontWidth = double.Parse(IniOper.getInstance().FontWidth);
            InitTextStyle("仿宋", font, fontWidth);
            InitTextStyle("SRB.HT", font, fontWidth);
            InitTextStyle("Standard", font, fontWidth);
            //钢筋字体
            string gjFontFileName = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Fonts\\tssdeng.shx";
            //InitTextStyle("SRB.tssdeng", font, gjFontFileName, 1);
            font = "FS-GB2312-Rebar";
            InitTextStyle("SRB.tssdeng", font, fontWidth);
            List<int> scaleList = new List<int>
            { 1
,5
,8
,10
,12
,15
,20
,25
,30
,40
,50
,60
,70
,75
,80
,100
,120
,125
,150
,200
,300
            };
            foreach (int scale in scaleList)
            {
                InitDimStyle(Unit.Centimeter, Unit.Centimeter, scale, "SRB.HT");
                InitDimStyle(Unit.Millimeter, Unit.Centimeter, scale, "SRB.HT");
                InitDimStyle(Unit.Millimeter, Unit.Millimeter, scale, "SRB.HT");
                InitLeaderStyle(scale);
            }
            InitBlock();
        }

        /// <summary>
        /// 初始化制图单位
        /// </summary>
        /// <param name="drawingUnit"></param>
        public static void InitUnits(UnitsValue drawingUnit = UnitsValue.Millimeters)
        {
            Database db = HostApplicationServices.WorkingDatabase;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                db.Insunits = drawingUnit;
                BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord ms = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                ms.Units = drawingUnit;
                tr.Commit();
            }
        }


        /// <summary>
        /// 标准图层配置
        /// </summary>
        public static void InitLayer()
        {
            Database acCurDb = HostApplicationServices.WorkingDatabase;
            using (Transaction tr = acCurDb.TransactionManager.StartTransaction())
            {
                Dictionary<string, short> ldic = new Dictionary<string, short>()
                {
                    #region 国标
                    ["H钢筋"] = 1,
                    ["H点筋"] = 6,
                    ["H粗线"] = 1,
                    ["H粗线_钢筋"] = 1,
                    ["H粗线_构造"] = 3,
                    ["H粗虚线"] = 3,
                    ["H细线"] = 4,
                    ["H细虚线"] = 2,
                    ["H虚线"] = 2,
                    ["H标注"] = 4,
                    ["H文本"] = 7,
                    ["TEXT(En)"] = 4,
                    ["TEXT(M)"] = 7,
                    ["H中心线"] = 2,
                    ["H墩身"] = 3,
                    ["H填充"] = 8,
                    ["H不打印"] = 1,
                    ["H不打印图框"] = 1,
                    ["H图框"] = 7,
                    #endregion
                    #region 欧标
                    //["H钢筋"] = 1,
                    //["H粗线"] = 1,
                    //["H细线"] = 5,
                    //["HM细线"] = 7,
                    //["H标注"] = 4,
                    //["H文本"] = 7,
                    //["TEXT(En)"] = 4,
                    //["TEXT(M)"] = 7,
                    //["H中心线"] = 2,
                    //["H虚线"] = 3,
                    #endregion
                    //["H标注"] = 7,
                };
                List<string> Lname = new List<string>() { "CONTINUOUS", "CENTER", "DASHED", "DASHED2" };
                LayerTable acLyrTbl;
                acLyrTbl = tr.GetObject(acCurDb.LayerTableId, OpenMode.ForRead) as LayerTable;
                LinetypeTable acLinTbl;
                acLinTbl = tr.GetObject(acCurDb.LinetypeTableId, OpenMode.ForRead) as LinetypeTable;
                foreach (string ltname in Lname)
                {
                    if (!acLinTbl.Has(ltname))
                    {
                        acCurDb.LoadLineTypeFile(ltname, "acad.lin");
                    }
                }
                LayerTableRecord acLyrTblRec = new LayerTableRecord();
                acLyrTblRec.UpgradeOpen();
                foreach (string key in ldic.Keys)
                {
                    short cid = ldic[key];
                    acLyrTblRec = new LayerTableRecord();
                    if (!acLyrTbl.Has(key))
                    {
                        acLyrTblRec.Color = Color.FromColorIndex(ColorMethod.ByAci, cid);
                        if ( key == "H墩身") { acLyrTblRec.LineWeight = LineWeight.LineWeight030; }
                        else if (key == "H钢筋" || key == "H点筋" || key == "H粗线"|| key == "H粗线_钢筋" || key == "H粗线_构造" || key == "H粗虚线") { acLyrTblRec.LineWeight = LineWeight.LineWeight025; }
                        else { acLyrTblRec.LineWeight = LineWeight.LineWeight015; }
                        if (key == "H中心线") { acLyrTblRec.LinetypeObjectId = acLinTbl["CENTER"]; }
                        else if (key == "H细虚线"|| key == "H虚线") { acLyrTblRec.LinetypeObjectId = acLinTbl["DASHED"]; }
                         else { acLyrTblRec.LinetypeObjectId = acLinTbl["CONTINUOUS"]; }
                        acLyrTblRec.Name = key;
                        if (acLyrTbl.IsWriteEnabled == false) acLyrTbl.UpgradeOpen();
                        acLyrTbl.Add(acLyrTblRec);
                        tr.AddNewlyCreatedDBObject(acLyrTblRec, true);
                    }
                    else
                    {
                        acLyrTblRec = tr.GetObject(acLyrTbl[key], OpenMode.ForWrite) as LayerTableRecord;
                        if (key == "H墩身") { acLyrTblRec.LineWeight = LineWeight.LineWeight030; }
                        else if (key == "H钢筋" || key == "H点筋" || key == "H粗线" || key == "H粗线_钢筋" || key == "H粗线_构造" || key == "H粗虚线") { acLyrTblRec.LineWeight = LineWeight.LineWeight025; }
                        else { acLyrTblRec.LineWeight = LineWeight.LineWeight015; }
                        if (key == "H中心线") { acLyrTblRec.LinetypeObjectId = acLinTbl["CENTER"]; }
                        else if (key == "H细虚线"|| key == "H虚线") { acLyrTblRec.LinetypeObjectId = acLinTbl["DASHED"]; }
                        else { acLyrTblRec.LinetypeObjectId = acLinTbl["CONTINUOUS"]; }                   
                        acLyrTblRec.Color = Color.FromColorIndex(ColorMethod.ByAci, cid);
                    }
                    if (!acLyrTbl.Has(key))
                    {
                        if (key == "H不打印"||key== "H不打印图框")
                        {
                            acLyrTblRec = tr.GetObject(acLyrTbl[key], OpenMode.ForWrite) as LayerTableRecord;
                            acLyrTblRec.Name = key;
                            acLyrTblRec.IsPlottable = false;
                            if (acLyrTbl.IsWriteEnabled == false) acLyrTbl.UpgradeOpen();
                            acLyrTbl.Add(acLyrTblRec);
                            tr.AddNewlyCreatedDBObject(acLyrTblRec, true);
                        }
                        if (key == "H填充")
                        {
                            acLyrTblRec = tr.GetObject(acLyrTbl[key], OpenMode.ForWrite) as LayerTableRecord;
                            acLyrTblRec.Name = key;
                            if (acLyrTbl.IsWriteEnabled == false) acLyrTbl.UpgradeOpen();
                            acLyrTbl.Add(acLyrTblRec);
                            tr.AddNewlyCreatedDBObject(acLyrTblRec, true);
                            byte value = (byte)((25500 - 255 * 40) / 100);
                            acLyrTblRec.Transparency = new Transparency(value);
                        }

                    }
                    else
                    {
                        acLyrTblRec = tr.GetObject(acLyrTbl[key], OpenMode.ForWrite) as LayerTableRecord;
                        if (key == "H不打印" || key == "H不打印图框") { acLyrTblRec.IsPlottable = false; ; }
                        if (key == "H填充")
                        {
                            byte value = (byte)((25500 - 255 * 40) / 100);
                            acLyrTblRec.Transparency = new Transparency(value);
                        }
                    }

                    //{
                    //    acLyrTblRec.Color = Color.FromColorIndex(ColorMethod.ByAci, cid);
                    //    if (cid != 1) { acLyrTblRec.LineWeight = LineWeight.LineWeight015; }
                    //    else { acLyrTblRec.LineWeight = LineWeight.LineWeight030; }
                    //    if (cid == 2) { acLyrTblRec.LinetypeObjectId = acLinTbl["CENTER"]; }
                    //    if (cid == 3) { acLyrTblRec.LinetypeObjectId = acLinTbl["DASHED"]; }
                    //    //if (cid == 4) { acLyrTblRec.LinetypeObjectId = acLinTbl["DASHED"]; }
                    //    if (cid == 8) { acLyrTblRec.IsPlottable = false; }
                    //    acLyrTblRec.Name = key;
                    //    if (acLyrTbl.IsWriteEnabled == false) acLyrTbl.UpgradeOpen();
                    //    acLyrTbl.Add(acLyrTblRec);
                    //    tr.AddNewlyCreatedDBObject(acLyrTblRec, true);
                    //}
                    //else
                    //{
                    //    acLyrTblRec = tr.GetObject(acLyrTbl[key], OpenMode.ForWrite) as LayerTableRecord;
                    //    if (cid != 1) { acLyrTblRec.LineWeight = LineWeight.LineWeight015; }
                    //    else { acLyrTblRec.LineWeight = LineWeight.LineWeight030; }
                    //    if (cid == 2) { acLyrTblRec.LinetypeObjectId = acLinTbl["CENTER"]; }
                    //    if (cid == 3) { acLyrTblRec.LinetypeObjectId = acLinTbl["DASHED"]; }
                    //    //if (cid == 4) { acLyrTblRec.LinetypeObjectId = acLinTbl["DASHED"]; }
                    //    if (cid == 8) { acLyrTblRec.IsPlottable = false; }
                    //    acLyrTblRec.Color = Color.FromColorIndex(ColorMethod.ByAci, cid);

                        //}
                }

              
                acLyrTblRec.DowngradeOpen();
                tr.Commit();
            }
        }

        /// <summary>
        /// 初始化文字样式
        /// </summary>
        /// <param name="StyleName">文字样式名称</param>
        /// <param name="FontName">字体名称</param>
        /// <param name="WidthFactor">宽度因子</param>
        /// <param name="charset">字符集，中文3212默认134</param>
        /// <param name="pf">字族，</param>
        public static void InitTextStyle(string StyleName, string FontName, double WidthFactor, int charset = 134, int pf = 48)
        {
            Database acCurDb = HostApplicationServices.WorkingDatabase;
            using (Transaction tr = acCurDb.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(acCurDb.TextStyleTableId, OpenMode.ForWrite) as TextStyleTable;
                TextStyleTableRecord acTextStyleTblRec;
                acTextStyleTblRec = tr.GetObject(acCurDb.Textstyle,
                                                     OpenMode.ForWrite) as TextStyleTableRecord;

                Teigha.GraphicsInterface.FontDescriptor acFont;
                acFont = acTextStyleTblRec.Font;

                #region 字体设置
                if (!st.Has(StyleName))//字体设置
                {
                    st.UpgradeOpen();
                    TextStyleTableRecord str = new TextStyleTableRecord()
                    {
                        Name = StyleName,
                        Font = new Teigha.GraphicsInterface.FontDescriptor(FontName, acFont.Bold, acFont.Italic, acFont.CharacterSet, acFont.PitchAndFamily),
                        XScale = WidthFactor,
                        TextSize = 0,

                    };
               
                    st.Add(str);
                    tr.AddNewlyCreatedDBObject(str, true);
                    st.DowngradeOpen();
                }
                else
                {
                    st.UpgradeOpen();
                    TextStyleTableRecord str = tr.GetObject(st[StyleName], OpenMode.ForWrite) as TextStyleTableRecord;
                    str.Font = new Teigha.GraphicsInterface.FontDescriptor(FontName, acFont.Bold, acFont.Italic, acFont.CharacterSet, acFont.PitchAndFamily);
                    str.XScale = WidthFactor;
                    str.TextSize = 0;
                    st.DowngradeOpen();
                }

                #endregion
                tr.Commit();
            }
        }

        /// <summary>
        /// 初始化文字样式
        /// </summary>
        /// <param name="StyleName">文字样式名称</param>
        /// <param name="FontName">字体名称</param>
        /// <param name="WidthFactor">宽度因子</param>
        /// <param name="charset">字符集，中文3212默认134</param>
        /// <param name="pf">字族，</param>
        public static void InitTextStyle(string StyleName, string FontName, string fronFileName, double WidthFactor)
        {
            Database acCurDb = HostApplicationServices.WorkingDatabase;
            using (Transaction tr = acCurDb.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(acCurDb.TextStyleTableId, OpenMode.ForWrite) as TextStyleTable;
                #region 字体设置
                if (!st.Has(StyleName))//字体设置
                {
                    TextStyleTableRecord str = new TextStyleTableRecord()
                    {
                        Name = StyleName,
                        FileName = fronFileName,
                        XScale = WidthFactor,
                        TextSize = 0,

                    };
                    st.Add(str);
                    tr.AddNewlyCreatedDBObject(str, true);
                }
                else
                {
                    TextStyleTableRecord str = tr.GetObject(st[StyleName], OpenMode.ForWrite) as TextStyleTableRecord;
                    str.FileName = fronFileName;
                    str.XScale = WidthFactor;
                    str.TextSize = 0;
                }

                #endregion
                tr.Commit();
            }
        }

        public static void InitLeaderStyle(double scale)
        {
            Database acCurDb = HostApplicationServices.WorkingDatabase;
            using (Transaction tr = acCurDb.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(acCurDb.TextStyleTableId, OpenMode.ForWrite) as TextStyleTable;
                #region 引线
                string StName = "ML";
                if (scale < 1)
                {
                    StName += Math.Round(1 / scale, 0).ToString() + "-1";
                }
                else
                {
                    StName += "1-" + scale.ToString();
                }
                DBDictionary mlstyles = (DBDictionary)tr.GetObject(acCurDb.MLeaderStyleDictionaryId, OpenMode.ForRead);
                MLeaderStyle mldst;
                if (!mlstyles.Contains(StName))
                {
                    mldst = new MLeaderStyle();
                    mldst.TextHeight = 2.5;
                    mldst.TextStyleId = st[Extensions.curFont];
                    mldst.ArrowSize = 0;
                    mldst.TextAlignAlwaysLeft = true;
                    //mldst.ExtendLeaderToText = false;

                    mldst.LandingGap = 0;
                    mldst.EnableDogleg = false;
                    mldst.TextAlignmentType = TextAlignmentType.LeftAlignment;
                    mldst.TextAttachmentDirection = TextAttachmentDirection.AttachmentHorizontal;
                    mldst.TextAngleType = TextAngleType.HorizontalAngle;
                    mldst.Scale = scale;
                    mldst.SetTextAttachmentType(TextAttachmentType.AttachmentBottomOfTopLine, LeaderDirectionType.LeftLeader);
                    mldst.SetTextAttachmentType(TextAttachmentType.AttachmentBottomOfTopLine, LeaderDirectionType.RightLeader);
                    ObjectId mLeaderStyle = mldst.PostMLeaderStyleToDb(acCurDb, StName);
                    tr.AddNewlyCreatedDBObject(mldst, true);
                }

                #endregion
                tr.Commit();
            }
        }


        /// <summary>
        /// 配置标注样式
        /// </summary>
        /// <param name="plotunit">绘图单位</param>
        /// <param name="paperunit">标注单位</param>
        /// <param name="scale">比例</param>
        /// <param name="tstyle">文字样式</param>
        public static void InitDimStyle(Unit plotunit, Unit paperunit, double scale, string tstyle)
        {
            Database db = HostApplicationServices.WorkingDatabase;

            Dictionary<Unit, double> UnitDic = new Dictionary<Unit, double>()
            {
                { Unit.Meter,1000 },
                { Unit.Centimeter,10 },
                { Unit.Millimeter,1 },
            };
            Dictionary<Unit, string> UnitDicStr = new Dictionary<Unit, string>()
            {
                { Unit.Meter,"M" },
                { Unit.Centimeter,"CM" },
                { Unit.Millimeter,"MM" },
            };
            double factor = UnitDic[plotunit] / UnitDic[paperunit];


            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                DimStyleTable dst = tr.GetObject(db.DimStyleTableId, OpenMode.ForWrite) as DimStyleTable;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                dst.UpgradeOpen();
                string DimStyleName = string.Format("{0}-{1}-", UnitDicStr[plotunit], UnitDicStr[paperunit]);
                if (scale < 1)
                {
                    DimStyleName += Math.Round(1 / scale, 0).ToString() + "-1";
                }
                else
                {
                    DimStyleName += "1-" + scale.ToString();
                }
                DimStyleTableRecord dstr = new DimStyleTableRecord();
                if (!dst.Has(DimStyleName))
                {

                    dstr.Name = DimStyleName;
                    dstr.Dimscale = scale;
                    dstr.Dimtxsty = st[tstyle];
                    //dstr.Dimclrd = Color.FromColorIndex(ColorMethod.ByAci, 6);
                    //dstr.Dimclre = Color.FromColorIndex(ColorMethod.ByAci, 6);
                    dstr.Dimdli = 5;
                    dstr.Dimsah = true;

                    //dstr.Dimblk = StyleTools.GetArrowObjectId(db,"_NONE");
                    //dstr.Dimblk1 = StyleTools.GetArrowObjectId(db, "_NONE");
                    //dstr.Dimblk2 = StyleTools.GetArrowObjectId(db, "_NONE");

                    //dstr.Dimblk = StyleTools.GetArrowObjectId(db, "_ARCHTICK");
                    //dstr.Dimblk1 = StyleTools.GetArrowObjectId(db, "_ARCHTICK");
                    //dstr.Dimblk2 = StyleTools.GetArrowObjectId(db, "_ARCHTICK");

                    dstr.Dimdle =2;
                    dstr.Dimexe = 1;
                    dstr.Dimexo = 1;
                    dstr.Dimclrd = Color.FromColorIndex(ColorMethod.ByAci, 4);
                    dstr.Dimclre = Color.FromColorIndex(ColorMethod.ByAci, 4);
                    //dstr.Dimfxlon = true;

                    dstr.DimfxlenOn = true;
                    dstr.Dimfxlen = 4;
                    //dstr.Dimfxlen = 4;
                    dstr.Dimtxt = 2.5;

                    dstr.Dimasz = 2;
                    dstr.Dimatfit = 0;
                    dstr.Dimtix = true;
                    dstr.Dimsoxd = false;
                    dstr.Dimtoh = true;                  
                    dstr.Dimtmove = 1;
                    //dstr.Dimtad = 1;
                    dstr.Dimgap = 0.6;
                    dstr.Dimdec = 0;
                    dstr.Dimtih = false;
                    dstr.Dimtoh = false;
                    dstr.Dimdsep = '.';
                    dstr.Dimlfac = factor;
                    dstr.Dimtofl = true;
                    dstr.Dimtad = 1;
                    dst.Add(dstr);
                    tr.AddNewlyCreatedDBObject(dstr, true);
                }
                else
                {
                    dstr = tr.GetObject(dst[DimStyleName], OpenMode.ForWrite) as DimStyleTableRecord;
                    dstr.Dimscale = scale;

                    dstr.Dimclrd = Color.FromColorIndex(ColorMethod.ByAci, 4);
                    dstr.Dimclre = Color.FromColorIndex(ColorMethod.ByAci, 4);
                    dstr.Dimdli = 5;
                    dstr.Dimsah = true;
                    //dstr.Dimblk = StyleTools.GetArrowObjectId(db, "_NONE");
                    //dstr.Dimblk1 = StyleTools.GetArrowObjectId(db, "_NONE");
                    //dstr.Dimblk2 = StyleTools.GetArrowObjectId(db, "_NONE");
                    //dstr.Dimblk = StyleTools.GetArrowObjectId(db, "_ARCHTICK");
                    //dstr.Dimblk1 = StyleTools.GetArrowObjectId(db, "_ARCHTICK");
                    //dstr.Dimblk2 = StyleTools.GetArrowObjectId(db, "_ARCHTICK");
                    dstr.Dimdle =1;//尺寸线   —  超出标记                
                    dstr.Dimexe = 1;//尺寸界线 —  超出尺寸线
                    dstr.Dimexo = 1;//尺寸界线 —  起点偏移量 
                    //dstr.DimfxlenOn = false;
                    //dstr.Dimfxlen = 4;

                    dstr.DimfxlenOn = true;
                    dstr.Dimfxlen = 4;
                    dstr.Dimtxt = 2.5;//文字 — 文字高度
                    dstr.Dimasz = 2;//符号和箭头  —  箭头大小
                    dstr.Dimatfit = 0;
                    dstr.Dimtix = true;
                    dstr.Dimsoxd = false;
                    dstr.Dimtoh = true;
                    dstr.Dimtmove = 1;
                    dstr.Dimtad = 1;
                    dstr.Dimgap = 0.6;//文字 — 从尺寸线偏移
                    dstr.Dimdec = 0;
                    dstr.Dimtih = false;
                    dstr.Dimtoh = false;
                    dstr.Dimtofl = true;
                    dstr.Dimdsep = '.';
                    dstr.Dimtxsty = st[tstyle];
                    dstr.Dimlfac = factor;
                
                }
                dst.DowngradeOpen();
                tr.Commit();
            }
        }


        public static void InitDimExtendStyle(Unit plotunit, Unit paperunit, double scale, double extendscale, string tstyle)
        {
            Database db = HostApplicationServices.WorkingDatabase;

            Dictionary<Unit, double> UnitDic = new Dictionary<Unit, double>()
            {
                { Unit.Meter,1000 },
                { Unit.Centimeter,10 },
                { Unit.Millimeter,1 },
            };
            Dictionary<Unit, string> UnitDicStr = new Dictionary<Unit, string>()
            {
                { Unit.Meter,"M" },
                { Unit.Centimeter,"CM" },
                { Unit.Millimeter,"MM" },
            };
            double factor = UnitDic[plotunit] / UnitDic[paperunit];


            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                DimStyleTable dst = tr.GetObject(db.DimStyleTableId, OpenMode.ForWrite) as DimStyleTable;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                dst.UpgradeOpen();
                string DimStyleName = string.Format("{0}-{1}-", UnitDicStr[plotunit], UnitDicStr[paperunit]);
                if (scale < 1)
                {
                    DimStyleName += Math.Round(1 / scale, 0).ToString() + "-1E";
                }
                else
                {
                    DimStyleName += "1E-" + scale.ToString();
                }
                DimStyleTableRecord dstr = new DimStyleTableRecord();
                if (!dst.Has(DimStyleName))
                {

                    dstr.Name = DimStyleName;
                    dstr.Dimscale = scale* extendscale;
                    dstr.Dimtxsty = st[tstyle];
                    //dstr.Dimclrd = Color.FromColorIndex(ColorMethod.ByAci, 6);
                    //dstr.Dimclre = Color.FromColorIndex(ColorMethod.ByAci, 6);
                    dstr.Dimdli = 5;
                    dstr.Dimsah = true;

                    //dstr.Dimblk = StyleTools.GetArrowObjectId(db,"_NONE");
                    //dstr.Dimblk1 = StyleTools.GetArrowObjectId(db, "_NONE");
                    //dstr.Dimblk2 = StyleTools.GetArrowObjectId(db, "_NONE");

                    //dstr.Dimblk = StyleTools.GetArrowObjectId(db, "_ARCHTICK");
                    //dstr.Dimblk1 = StyleTools.GetArrowObjectId(db, "_ARCHTICK");
                    //dstr.Dimblk2 = StyleTools.GetArrowObjectId(db, "_ARCHTICK");

                    dstr.Dimdle = 2;
                    dstr.Dimexe = 1;
                    dstr.Dimexo = 1;
                    dstr.Dimclrd = Color.FromColorIndex(ColorMethod.ByAci, 4);
                    dstr.Dimclre = Color.FromColorIndex(ColorMethod.ByAci, 4);
                    //dstr.Dimfxlon = true;

                    dstr.DimfxlenOn = true;
                    dstr.Dimfxlen = 4;
                    //dstr.Dimfxlen = 4;
                    dstr.Dimtxt = 2.5;

                    dstr.Dimasz = 2;
                    dstr.Dimatfit = 0;
                    dstr.Dimtix = true;
                    dstr.Dimsoxd = false;
                    dstr.Dimtoh = true;
                    dstr.Dimtmove = 1;
                    //dstr.Dimtad = 1;
                    dstr.Dimgap = 0.6;
                    dstr.Dimdec = 0;
                    dstr.Dimtih = false;
                    dstr.Dimtoh = false;
                    dstr.Dimdsep = '.';
                    dstr.Dimlfac = factor;
                    dstr.Dimtofl = true;
                    dstr.Dimtad = 1;
                    dst.Add(dstr);
                    tr.AddNewlyCreatedDBObject(dstr, true);
                }
                else
                {
                    dstr = tr.GetObject(dst[DimStyleName], OpenMode.ForWrite) as DimStyleTableRecord;
                    dstr.Dimscale = scale*extendscale;

                    dstr.Dimclrd = Color.FromColorIndex(ColorMethod.ByAci, 4);
                    dstr.Dimclre = Color.FromColorIndex(ColorMethod.ByAci, 4);
                    dstr.Dimdli = 5;
                    dstr.Dimsah = true;
                    //dstr.Dimblk = StyleTools.GetArrowObjectId(db, "_NONE");
                    //dstr.Dimblk1 = StyleTools.GetArrowObjectId(db, "_NONE");
                    //dstr.Dimblk2 = StyleTools.GetArrowObjectId(db, "_NONE");
                    //dstr.Dimblk = StyleTools.GetArrowObjectId(db, "_ARCHTICK");
                    //dstr.Dimblk1 = StyleTools.GetArrowObjectId(db, "_ARCHTICK");
                    //dstr.Dimblk2 = StyleTools.GetArrowObjectId(db, "_ARCHTICK");
                    dstr.Dimdle = 1;//尺寸线   —  超出标记                
                    dstr.Dimexe = 1;//尺寸界线 —  超出尺寸线
                    dstr.Dimexo = 1;//尺寸界线 —  起点偏移量 
                    //dstr.DimfxlenOn = false;
                    //dstr.Dimfxlen = 4;

                    dstr.DimfxlenOn = true;
                    dstr.Dimfxlen = 4;
                    dstr.Dimtxt = 2.5;//文字 — 文字高度
                    dstr.Dimasz = 2;//符号和箭头  —  箭头大小
                    dstr.Dimatfit = 0;
                    dstr.Dimtix = true;
                    dstr.Dimsoxd = false;
                    dstr.Dimtoh = true;
                    dstr.Dimtmove = 1;
                    dstr.Dimtad = 1;
                    dstr.Dimgap = 0.6;//文字 — 从尺寸线偏移
                    dstr.Dimdec = 0;
                    dstr.Dimtih = false;
                    dstr.Dimtoh = false;
                    dstr.Dimtofl = true;
                    dstr.Dimdsep = '.';
                    dstr.Dimtxsty = st[tstyle];
                    dstr.Dimlfac = factor;

                }
                dst.DowngradeOpen();
                tr.Commit();
            }
        }

        /// <summary>
        /// 初始化文字比例图块
        /// </summary>
        public static void InitBlock()
        {
            Database acCurDb = HostApplicationServices.WorkingDatabase;

            using (Transaction tr = acCurDb.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(acCurDb.TextStyleTableId, OpenMode.ForWrite) as TextStyleTable;

                #region 自定义块
                BlockTable bt = (BlockTable)tr.GetObject(acCurDb.BlockTableId, OpenMode.ForRead);
                BlockTableRecord btr = new BlockTableRecord();
                if (!bt.Has("BG"))
                {
                    btr = new BlockTableRecord();
                    btr.Name = "BG";
                    bt.UpgradeOpen();
                    bt.Add(btr);
                    tr.AddNewlyCreatedDBObject(btr, true);
                    Teigha.DatabaseServices.Polyline Paa = new Teigha.DatabaseServices.Polyline();
                    Paa.AddVertexAt(0, new Point2d(0, 0), 0, 0, 0);
                    Paa.AddVertexAt(1, new Point2d(250 / Math.Sqrt(3), 250), 0, 0, 0);
                    Paa.AddVertexAt(2, new Point2d(-250 / Math.Sqrt(3), 250), 0, 0, 0);
                    Paa.Closed = true;
                    btr.AppendEntity(Paa);
                    tr.AddNewlyCreatedDBObject(Paa, true);

                    Line Laa = new Line(new Point3d(-250 / Math.Sqrt(3), 0, 0), new Point3d(1275, 0, 0));
                    btr.AppendEntity(Laa);
                    tr.AddNewlyCreatedDBObject(Laa, true);

                    AttributeDefinition curbg = new AttributeDefinition();
                    curbg.Position = new Point3d(175, 80, 0);
                    curbg.Height = 250;
                    curbg.WidthFactor = st[Extensions.curFont].GetXScale();
                    curbg.Tag = "H标高";
                    curbg.TextStyleId = st[Extensions.curFont];
                    btr.AppendEntity(curbg);
                    tr.AddNewlyCreatedDBObject(curbg, true);
                }
                if (!bt.Has("BGMark"))
                {
                    btr = new BlockTableRecord();
                    btr.Name = "BGMark";
                    bt.UpgradeOpen();
                    bt.Add(btr);
                    tr.AddNewlyCreatedDBObject(btr, true);
                    Teigha.DatabaseServices.Polyline Paa = new Teigha.DatabaseServices.Polyline();
                    Paa.AddVertexAt(0, new Point2d(0, 0), 0, 0, 0);
                    Paa.AddVertexAt(1, new Point2d(350 / Math.Sqrt(3), 250), 0, 0, 0);
                    Paa.AddVertexAt(2, new Point2d(-350 / Math.Sqrt(3), 250), 0, 0, 0);
                    Paa.Closed = true;
                    btr.AppendEntity(Paa);
                    tr.AddNewlyCreatedDBObject(Paa, true);

                    Line Laa = new Line(new Point3d(-350 / Math.Sqrt(3), 0, 0), new Point3d(850, 0, 0));
                    btr.AppendEntity(Laa);
                    tr.AddNewlyCreatedDBObject(Laa, true);

                    AttributeDefinition curbg = new AttributeDefinition();
                    curbg.Position = new Point3d(350, 80, 0);
                    curbg.Height = 350;
                    curbg.WidthFactor = st[Extensions.curFont].GetXScale();
                    curbg.Tag = "H标高";
                    curbg.TextStyleId = st[Extensions.curFont];
                    btr.AppendEntity(curbg);
                    tr.AddNewlyCreatedDBObject(curbg, true);
                }
                if (!bt.Has("Mark"))
                {
                    btr = new BlockTableRecord();
                    btr.Name = "Mark";
                    bt.UpgradeOpen();
                    bt.Add(btr);
                    tr.AddNewlyCreatedDBObject(btr, true);
                    Polyline Paa = new Polyline();
                    Paa.AddVertexAt(0, new Point2d(0, -10), 0, 5, 5);
                    Paa.AddVertexAt(1, new Point2d(0, 450), 0, 5, 5);
                    btr.AppendEntity(Paa);
                    tr.AddNewlyCreatedDBObject(Paa, true);
                    AttributeDefinition curbg = new AttributeDefinition();
                    curbg.Position = new Point3d(60, 50, 0);
                    curbg.Height = 350;
                    curbg.WidthFactor = st[Extensions.curFont].GetXScale();
                    curbg.Tag = "剖切线";
                    curbg.TextStyleId = st[Extensions.curFont];
                    btr.AppendEntity(curbg);
                    tr.AddNewlyCreatedDBObject(curbg, true);
                }
                if (!bt.Has("RMark"))
                {
                    btr = new BlockTableRecord();
                    btr.Name = "RMark";
                    bt.UpgradeOpen();
                    bt.Add(btr);
                    tr.AddNewlyCreatedDBObject(btr, true);
                    Polyline Paa = new Polyline();
                    Paa.AddVertexAt(0, new Point2d(450, -10), 0, 5, 5);
                    Paa.AddVertexAt(1, new Point2d(450, 450), 0, 5, 5);
                    btr.AppendEntity(Paa);
                    tr.AddNewlyCreatedDBObject(Paa, true);
                    AttributeDefinition curbg = new AttributeDefinition();
                    curbg.Position = new Point3d(60, 50, 0);
                    curbg.Height = 350;
                    curbg.WidthFactor = st[Extensions.curFont].GetXScale();
                    curbg.Tag = "剖切线";
                    curbg.TextStyleId = st[Extensions.curFont];
                    btr.AppendEntity(curbg);
                    tr.AddNewlyCreatedDBObject(curbg, true);
                }
                if (!bt.Has("LRMarkT"))
                {
                    btr = new BlockTableRecord();
                    btr.Name = "LRMarkT";
                    bt.UpgradeOpen();
                    bt.Add(btr);
                    tr.AddNewlyCreatedDBObject(btr, true);
                    Polyline Paa = new Polyline();
                    Paa.AddVertexAt(0, new Point2d(0, 450), 0, 10, 10);
                    Paa.AddVertexAt(1, new Point2d(350, 450), 0, 10, 10);
                    btr.AppendEntity(Paa);
                    tr.AddNewlyCreatedDBObject(Paa, true);
                    AttributeDefinition curbg = new AttributeDefinition();
                    curbg.Position = new Point3d(65, 0, 0);
                    curbg.Height = 350;
                    curbg.WidthFactor = st[Extensions.curFont].GetXScale();
                    curbg.Tag = "剖切线";
                    curbg.TextStyleId = st[Extensions.curFont];
                    btr.AppendEntity(curbg);
                    tr.AddNewlyCreatedDBObject(curbg, true);
                }
                if (!bt.Has("LRMarkB"))
                {
                    btr = new BlockTableRecord();
                    btr.Name = "LRMarkB";
                    bt.UpgradeOpen();
                    bt.Add(btr);
                    tr.AddNewlyCreatedDBObject(btr, true);
                    Polyline Paa = new Polyline();
                    Paa.AddVertexAt(0, new Point2d(0, 0), 0, 10, 10);
                    Paa.AddVertexAt(1, new Point2d(350,0), 0, 10, 10);
                    btr.AppendEntity(Paa);
                    tr.AddNewlyCreatedDBObject(Paa, true);
                    AttributeDefinition curbg = new AttributeDefinition();
                    curbg.Position = new Point3d(100, 40, 0);
                    curbg.Height = 350;
                    curbg.WidthFactor = st[Extensions.curFont].GetXScale();
                    curbg.Tag = "剖切线";
                    curbg.TextStyleId = st[Extensions.curFont];
                    btr.AppendEntity(curbg);
                    tr.AddNewlyCreatedDBObject(curbg, true);
                }
                //-------------------------------------------------------------------------------------------
                if (!bt.Has("RightP"))
                {
                    BlockTableRecord btr2 = new BlockTableRecord();
                    btr2.Name = "RightP";
                    bt.UpgradeOpen();
                    bt.Add(btr2);
                    tr.AddNewlyCreatedDBObject(btr2, true);

                    Solid Array = new Solid(
                        new Point3d(774.9048 - 974.2305, 49.6974, 0),
                        new Point3d(710.2305 - 974.2305, 0, 0),
                        new Point3d(974.2305 - 974.2305, 0, 0)
                        )
                    { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                    btr2.AppendEntity(Array);
                    tr.AddNewlyCreatedDBObject(Array, true);

                    Line L = new Line(new Point3d(974.2305 - 974.2305, 0, 0),
                        new Point3d(-225.7695 - 974.2305, 0, 0))
                    { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                    btr2.AppendEntity(L);
                    tr.AddNewlyCreatedDBObject(L, true);

                    AttributeDefinition curzp = new AttributeDefinition();
                    curzp.Position = new Point3d(-160 - 974.2305, 73.1925, 0);
                    curzp.Height = 350;
                    curzp.WidthFactor = st[Extensions.curFont].GetXScale();
                    curzp.Tag = "右剖切线";
                    curzp.TextStyleId = st[Extensions.curFont];
                    btr2.AppendEntity(curzp);
                    tr.AddNewlyCreatedDBObject(curzp, true);
                }


                //-------------------------------------------------------------------------------------------
                if (!bt.Has("LeftP"))
                {
                    BlockTableRecord btr2 = new BlockTableRecord();
                    btr2.Name = "LeftP";
                    bt.UpgradeOpen();
                    bt.Add(btr2);
                    tr.AddNewlyCreatedDBObject(btr2, true);

                    Solid Array = new Solid(
                        new Point3d(-184.6346, 49.6974, 0),
                        new Point3d(-119.9603, 0, 0),
                        new Point3d(-383.9603, 0, 0)
                        )
                    { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                    btr2.AppendEntity(Array);
                    tr.AddNewlyCreatedDBObject(Array, true);

                    Line L = new Line(new Point3d(-383.9603, 0, 0), new Point3d(816.0397, 0, 0))
                    { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                    btr2.AppendEntity(L);
                    tr.AddNewlyCreatedDBObject(L, true);

                    AttributeDefinition curzp = new AttributeDefinition();
                    curzp.Position = new Point3d(-160, 73.1925, 0);
                    curzp.Height = 350;
                    curzp.WidthFactor = st[Extensions.curFont].GetXScale();
                    curzp.Tag = "左剖切线";
                    curzp.TextStyleId = st[Extensions.curFont];
                    btr2.AppendEntity(curzp);
                    tr.AddNewlyCreatedDBObject(curzp, true);
                }
                //-------------------------------------------------------------------------------------------
                if (!bt.Has("TopMark"))
                {
                    BlockTableRecord btr2 = new BlockTableRecord();
                    btr2.Name = "TopMark";
                    bt.UpgradeOpen();
                    bt.Add(btr2);
                    tr.AddNewlyCreatedDBObject(btr2, true);

                    Solid Array = new Solid(
                        new Point3d(774.9048 - 374.2305, 49.6974, 0),
                        new Point3d(710.2305 - 374.2305, 0, 0),
                        new Point3d(974.2305 - 374.2305, 0, 0)
                        )
                    { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                    btr2.AppendEntity(Array);
                    tr.AddNewlyCreatedDBObject(Array, true);
                    Polyline L = new Polyline() { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                    L.AddVertexAt(0, new Point2d(974.2305 - 374.2305, 0), 0, 0, 0);
                    L.AddVertexAt(1, new Point2d(374.2305 - 374.2305, 0), 0, 5, 5);
                    L.AddVertexAt(2, new Point2d(374.2305 - 374.2305, -400), 0, 5, 5);

                    btr2.AppendEntity(L);
                    tr.AddNewlyCreatedDBObject(L, true);

                    AttributeDefinition curzp = new AttributeDefinition();
                    curzp.Position = new Point3d(474 - 374.2305, -400, 0);
                    curzp.Height = 350;
                    curzp.WidthFactor = st[Extensions.curFont].GetXScale();
                    curzp.Tag = "A";
                    curzp.TextStyleId = st[Extensions.curFont];
                    btr2.AppendEntity(curzp);
                    tr.AddNewlyCreatedDBObject(curzp, true);
                }


                //-------------------------------------------------------------------------------------------
                if (!bt.Has("BottomMark"))
                {
                    BlockTableRecord btr2 = new BlockTableRecord();
                    btr2.Name = "BottomMark";
                    bt.UpgradeOpen();
                    bt.Add(btr2);
                    tr.AddNewlyCreatedDBObject(btr2, true);

                    Solid Array = new Solid(
                       new Point3d(774.9048 - 374.2305, -49.6974, 0),
                       new Point3d(710.2305 - 374.2305, 0, 0),
                       new Point3d(974.2305 - 374.2305, 0, 0)
                       )
                    { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                    btr2.AppendEntity(Array);
                    tr.AddNewlyCreatedDBObject(Array, true);
                    Polyline L = new Polyline() { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                    L.AddVertexAt(0, new Point2d(974.2305 - 374.2305, 0), 0, 0, 0);
                    L.AddVertexAt(1, new Point2d(374.2305 - 374.2305, 0), 0, 5, 5);
                    L.AddVertexAt(2, new Point2d(374.2305 - 374.2305, 400), 0, 5, 5);

                    btr2.AppendEntity(L);
                    tr.AddNewlyCreatedDBObject(L, true);

                    AttributeDefinition curzp = new AttributeDefinition();
                    curzp.Position = new Point3d(474 - 374.2305, 73.1925, 0);
                    curzp.Height = 350;
                    curzp.WidthFactor = st[Extensions.curFont].GetXScale();
                    curzp.Tag = "A";
                    curzp.TextStyleId = st[Extensions.curFont];
                    btr2.AppendEntity(curzp);
                    tr.AddNewlyCreatedDBObject(curzp, true);
                }

                if (!bt.Has("TTP"))
                {
                    BlockTableRecord btr2 = new BlockTableRecord();
                    btr2.Name = "TTP";
                    bt.UpgradeOpen();
                    bt.Add(btr2);
                    tr.AddNewlyCreatedDBObject(btr2, true);

                    Solid Array = new Solid(
                        new Point3d(49.6974, 774.9048 - 974.2305, 0),
                        new Point3d(0, 710.2305 - 974.2305, 0),
                        new Point3d(0, 974.2305 - 974.2305, 0)
                        )
                    { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                    btr2.AppendEntity(Array);
                    tr.AddNewlyCreatedDBObject(Array, true);

                    Line L = new Line(new Point3d(0, 974.2305 - 974.2305, 0), new Point3d(0, -225.7695 - 974.2305, 0))
                    { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                    btr2.AppendEntity(L);
                    tr.AddNewlyCreatedDBObject(L, true);

                    AttributeDefinition curzp = new AttributeDefinition();
                    curzp.Position = new Point3d(373.1925, -60 - 974.2305, 0);
                    curzp.Height = 350;
                    curzp.Rotation = GeTools.DegreeToRadian(90);
                    curzp.WidthFactor = st[Extensions.curFont].GetXScale();
                    curzp.Tag = "上坡";
                    curzp.TextStyleId = st[Extensions.curFont];
                    btr2.AppendEntity(curzp);
                    tr.AddNewlyCreatedDBObject(curzp, true);
                }
               
                if (!bt.Has("LeftMark"))
                {
                    BlockTableRecord btr2 = new BlockTableRecord();
                    btr2.Name = "LeftMark";
                    bt.UpgradeOpen();
                    bt.Add(btr2);
                    tr.AddNewlyCreatedDBObject(btr2, true);

                    Solid Array = new Solid(
                       new Point3d(-49.6974, -184.6346, 0),
                       new Point3d(0, -119.9603, 0),
                       new Point3d(0, -383.9603, 0)
                       )
                    { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                    btr2.AppendEntity(Array);
                    tr.AddNewlyCreatedDBObject(Array, true);
                    Polyline L = new Polyline() { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                    L.AddVertexAt(0, new Point2d(0, -383.9603), 0, 0, 0);
                    L.AddVertexAt(1, new Point2d(0, -383.9603 + 600), 0, 5, 5);
                    L.AddVertexAt(2, new Point2d(400, -383.9603 + 600), 0, 5, 5);
                    //Line L = new Line(new Point3d(974.2305 - 974.2305, 0, 0), new Point3d(-225.7695 - 974.2305, 0, 0))
                    //{ Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                    btr2.AppendEntity(L);
                    tr.AddNewlyCreatedDBObject(L, true);

                    AttributeDefinition curzp = new AttributeDefinition();
                    curzp.Position = new Point3d(110, -240, 0);
                    curzp.Height = 350;
                    curzp.WidthFactor = st[Extensions.curFont].GetXScale();
                    curzp.Tag = "B";
                    curzp.TextStyleId = st[Extensions.curFont];
                    btr2.AppendEntity(curzp);
                    tr.AddNewlyCreatedDBObject(curzp, true);
                }


                //-------------------------------------------------------------------------------------------
                if (!bt.Has("RightMark"))
                {
                    BlockTableRecord btr2 = new BlockTableRecord();
                    btr2.Name = "RightMark";
                    bt.UpgradeOpen();
                    bt.Add(btr2);
                    tr.AddNewlyCreatedDBObject(btr2, true);

                    Solid Array = new Solid(
                        new Point3d(49.6974, -184.6346, 0),
                        new Point3d(0, -119.9603, 0),
                        new Point3d(0, -383.9603, 0)
                        )
                    { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                    btr2.AppendEntity(Array);
                    tr.AddNewlyCreatedDBObject(Array, true);
                    Polyline L = new Polyline() { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                    L.AddVertexAt(0, new Point2d(0, -383.9603), 0, 0, 0);
                    L.AddVertexAt(1, new Point2d(0, -383.9603 + 600), 0, 5, 5);
                    L.AddVertexAt(2, new Point2d(-400, -383.9603 + 600), 0, 5, 5);
                    btr2.AppendEntity(L);
                    tr.AddNewlyCreatedDBObject(L, true);

                    AttributeDefinition curzp = new AttributeDefinition();
                    curzp.Position = new Point3d(-373.1925+60, -240, 0);
                    curzp.Height = 350;
                    curzp.WidthFactor = st[Extensions.curFont].GetXScale();
                    curzp.Tag = "B";
                    curzp.TextStyleId = st[Extensions.curFont];
                    btr2.AppendEntity(curzp);
                    tr.AddNewlyCreatedDBObject(curzp, true);
                }
                #endregion
                tr.Commit();
            }
        }

        #region 无界面添加绘图标准

        public static void InitStandardConfig(Database db, string bridgeId)
        {
            try
            {
                InitLayer(db);
                //字体
                string font = "仿宋_GB2312";
                if (!string.IsNullOrWhiteSpace(IniOper.getInstance().Font))
                    font = IniOper.getInstance().Font;
                //字体宽度
                double fontWidth = 0.75;
                if (!string.IsNullOrWhiteSpace(IniOper.getInstance().FontWidth))
                    fontWidth = double.Parse(IniOper.getInstance().FontWidth);

                List<int> scaleList = new List<int>
            { 1
,5
,8
,10
,12
,15
,20
,25
,30
,40
,50
,60
,70
,75
,80
,100
,120
,125
,150
,200
,225
,250
,300
            };
                //读取桥梁配置
                string sqlBridgeConfig = "select * from busi_project_config where bridge_id='" + bridgeId + "'";
                dtProjectConfig = MySqlHelper.ExecuteDataTable(sqlBridgeConfig, CommandType.Text);
                if (dtProjectConfig.Rows.Count > 0)
                {
                    string selectfont = dtProjectConfig.Rows[0]["font"].ToString();
                    double selectfontwidth = double.Parse(dtProjectConfig.Rows[0]["font_width"].ToString());
                    string selectscalelist = dtProjectConfig.Rows[0]["pf_scalelist"].ToString();
                    if (!string.IsNullOrEmpty(selectfont))
                    {
                        switch (selectfont)
                        {
                            case "0":
                                font = "仿宋_GB2312";
                                break;
                            case "1":
                                font = "romans.shx";
                                break;
                            case "2":
                                font = "Ariar";
                                break;
                            default:
                                font = "仿宋_GB2312";
                                break;
                        }
                    }
                    if (selectfontwidth != 0)
                    {
                        fontWidth = selectfontwidth;
                    }
                    if (!string.IsNullOrEmpty(selectscalelist))
                    {
                        string[] numbers = selectscalelist.Split(',');
                        scaleList.Clear();
                        foreach (string number in numbers)
                        {
                            int value;
                            if (int.TryParse(number, out value))
                            {
                                scaleList.Add(value);
                            }
                        }
                    }
                }

                InitLayer(db);
                InitTextStyle(db, "仿宋", font, fontWidth);
                InitTextStyle(db, "SRB.HT", font, fontWidth);
                InitTextStyle(db, "Standard", font, fontWidth);
                //钢筋字体
                string gjFontFileName = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Fonts\\tssdeng.shx";
                //InitTextStyle("SRB.tssdeng", font, gjFontFileName, 1);
                font = "FS-GB2312-Rebar";
                InitTextStyle(db, "SRB.tssdeng", font, fontWidth);
                
                foreach (int scale in scaleList)
                {
                    InitDimStyle(db, Unit.Centimeter, Unit.Centimeter, scale, "SRB.HT");
                    InitDimStyle(db, Unit.Millimeter, Unit.Centimeter, scale, "SRB.HT");
                    InitDimStyle(db, Unit.Millimeter, Unit.Millimeter, scale, "SRB.HT");
                    InitLeaderStyle(db, scale);
                }
                InitBlock(db);
            }
            catch(Exception ex)
            {
                new WriteLogs().writeLogs("绘图规则初始化异常：异常原因"+ex.ToString(), "exelog");
            }
        }

        /// <summary>
        /// 初始化制图单位
        /// </summary>
        /// <param name="drawingUnit"></param>
        public static void InitUnits(Database db,UnitsValue drawingUnit = UnitsValue.Millimeters)
        {
            //Database db = HostApplicationServices.WorkingDatabase;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                db.Insunits = drawingUnit;
                BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord ms = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                ms.Units = drawingUnit;
                tr.Commit();
            }
        }


        /// <summary>
        /// 标准图层配置
        /// </summary>
        public static void InitLayer(Database acCurDb)
        { 
            
            new WriteLogs().writeLogs("图层初始化", "exelog");
            try
            {
                //Database acCurDb = HostApplicationServices.WorkingDatabase;
                using (Transaction tr = acCurDb.TransactionManager.StartTransaction())
                {
                    Dictionary<string, short> ldic = new Dictionary<string, short>()
                    {
                        #region 国标
                        ["H钢筋"] = 1,
                        ["H点筋"] = 6,
                        ["H粗线"] = 1,
                        ["H粗线_钢筋"] = 1,
                        ["H粗线_构造"] = 3,
                        ["H粗虚线"] = 3,
                        ["H细线"] = 4,
                        ["H细虚线"] = 2,
                        ["H虚线"] = 2,
                        ["H标注"] = 4,
                        ["H文本"] = 7,
                        ["TEXT(En)"] = 4,
                        ["TEXT(M)"] = 7,
                        ["H中心线"] = 2,
                        ["H墩身"] = 3,
                        ["H填充"] = 8,
                        ["H不打印"] = 1,
                        ["H不打印图框"] = 9,
                        ["H图框"] = 7,
                        #endregion
                        #region 欧标
                        //["H钢筋"] = 1,
                        //["H粗线"] = 1,
                        //["H细线"] = 5,
                        //["HM细线"] = 7,
                        //["H标注"] = 4,
                        //["H文本"] = 7,
                        //["TEXT(En)"] = 4,
                        //["TEXT(M)"] = 7,
                        //["H中心线"] = 2,
                        //["H虚线"] = 3,
                        #endregion
                        //["H标注"] = 7,
                    };
                    List<string> Lname = new List<string>() { "CONTINUOUS", "CENTER", "DASHED", "DASHED2" };
                    LayerTable acLyrTbl;
                    acLyrTbl = tr.GetObject(acCurDb.LayerTableId, OpenMode.ForWrite) as LayerTable;
                    LinetypeTable acLinTbl;
                    acLinTbl = tr.GetObject(acCurDb.LinetypeTableId, OpenMode.ForRead) as LinetypeTable;
                    foreach (string ltname in Lname)
                    {
                        if (!acLinTbl.Has(ltname))
                        {
                            acCurDb.LoadLineTypeFile(ltname, "acad.lin");
                        }
                    }
                    LayerTableRecord acLyrTblRec = new LayerTableRecord();
                    acLyrTblRec.UpgradeOpen();
                    foreach (string key in ldic.Keys)
                    {
                        short cid = ldic[key];
                        acLyrTblRec = new LayerTableRecord();
                        if (!acLyrTbl.Has(key))
                        {
                            acLyrTblRec.Color = Color.FromColorIndex(ColorMethod.ByAci, cid);
                            if (key == "H墩身") { acLyrTblRec.LineWeight = LineWeight.LineWeight030; }
                            else if (key == "H钢筋" || key == "H点筋" || key == "H粗线" || key == "H粗线_钢筋" || key == "H粗线_构造" || key == "H粗虚线") { acLyrTblRec.LineWeight = LineWeight.LineWeight025; }
                            else { acLyrTblRec.LineWeight = LineWeight.LineWeight015; }
                            if (key == "H中心线") { acLyrTblRec.LinetypeObjectId = acLinTbl["CENTER"]; }
                            else if (key == "H细虚线" || key == "H虚线") { acLyrTblRec.LinetypeObjectId = acLinTbl["DASHED"]; }
                            else { acLyrTblRec.LinetypeObjectId = acLinTbl["CONTINUOUS"]; }
                            acLyrTblRec.Name = key;
                            if (acLyrTbl.IsWriteEnabled == false) acLyrTbl.UpgradeOpen();
                            acLyrTbl.Add(acLyrTblRec);
                            tr.AddNewlyCreatedDBObject(acLyrTblRec, true);
                        }
                        else
                        {
                            acLyrTblRec = tr.GetObject(acLyrTbl[key], OpenMode.ForWrite) as LayerTableRecord;
                            if (key == "H墩身") { acLyrTblRec.LineWeight = LineWeight.LineWeight030; }
                            else if (key == "H钢筋" || key == "H点筋" || key == "H粗线" || key == "H粗线_钢筋" || key == "H粗线_构造" || key == "H粗虚线") { acLyrTblRec.LineWeight = LineWeight.LineWeight025; }
                            else { acLyrTblRec.LineWeight = LineWeight.LineWeight015; }
                            if (key == "H中心线") { acLyrTblRec.LinetypeObjectId = acLinTbl["CENTER"]; }
                            else if (key == "H细虚线" || key == "H虚线") { acLyrTblRec.LinetypeObjectId = acLinTbl["DASHED"]; }
                            else { acLyrTblRec.LinetypeObjectId = acLinTbl["CONTINUOUS"]; }
                            acLyrTblRec.Color = Color.FromColorIndex(ColorMethod.ByAci, cid);
                        }
                        if (!acLyrTbl.Has(key))
                        {
                            if (key == "H不打印"||key== "H不打印图框")
                            {
                                acLyrTblRec = tr.GetObject(acLyrTbl[key], OpenMode.ForWrite) as LayerTableRecord;
                                acLyrTblRec.Name = key;
                                acLyrTblRec.IsPlottable = false;
                                if (acLyrTbl.IsWriteEnabled == false) acLyrTbl.UpgradeOpen();
                                acLyrTbl.Add(acLyrTblRec);
                                tr.AddNewlyCreatedDBObject(acLyrTblRec, true);
                            }
                            if (key == "H填充")
                            {
                                acLyrTblRec = tr.GetObject(acLyrTbl[key], OpenMode.ForWrite) as LayerTableRecord;
                                acLyrTblRec.Name = key;
                                if (acLyrTbl.IsWriteEnabled == false) acLyrTbl.UpgradeOpen();
                                acLyrTbl.Add(acLyrTblRec);
                                tr.AddNewlyCreatedDBObject(acLyrTblRec, true);
                                byte value = (byte)((25500 - 255 * 40) / 100);
                                acLyrTblRec.Transparency = new Transparency(value);
                            }

                        }
                        else
                        {
                            acLyrTblRec = tr.GetObject(acLyrTbl[key], OpenMode.ForWrite) as LayerTableRecord;
                            if (key == "H不打印" || key == "H不打印图框") { acLyrTblRec.IsPlottable = false; ; }
                            if (key == "H填充")
                            {
                                byte value = (byte)((25500 - 255 * 40) / 100);
                                acLyrTblRec.Transparency = new Transparency(value);
                            }
                        }

                        //{
                        //    acLyrTblRec.Color = Color.FromColorIndex(ColorMethod.ByAci, cid);
                        //    if (cid != 1) { acLyrTblRec.LineWeight = LineWeight.LineWeight015; }
                        //    else { acLyrTblRec.LineWeight = LineWeight.LineWeight030; }
                        //    if (cid == 2) { acLyrTblRec.LinetypeObjectId = acLinTbl["CENTER"]; }
                        //    if (cid == 3) { acLyrTblRec.LinetypeObjectId = acLinTbl["DASHED"]; }
                        //    //if (cid == 4) { acLyrTblRec.LinetypeObjectId = acLinTbl["DASHED"]; }
                        //    if (cid == 8) { acLyrTblRec.IsPlottable = false; }
                        //    acLyrTblRec.Name = key;
                        //    if (acLyrTbl.IsWriteEnabled == false) acLyrTbl.UpgradeOpen();
                        //    acLyrTbl.Add(acLyrTblRec);
                        //    tr.AddNewlyCreatedDBObject(acLyrTblRec, true);
                        //}
                        //else
                        //{
                        //    acLyrTblRec = tr.GetObject(acLyrTbl[key], OpenMode.ForWrite) as LayerTableRecord;
                        //    if (cid != 1) { acLyrTblRec.LineWeight = LineWeight.LineWeight015; }
                        //    else { acLyrTblRec.LineWeight = LineWeight.LineWeight030; }
                        //    if (cid == 2) { acLyrTblRec.LinetypeObjectId = acLinTbl["CENTER"]; }
                        //    if (cid == 3) { acLyrTblRec.LinetypeObjectId = acLinTbl["DASHED"]; }
                        //    //if (cid == 4) { acLyrTblRec.LinetypeObjectId = acLinTbl["DASHED"]; }
                        //    if (cid == 8) { acLyrTblRec.IsPlottable = false; }
                        //    acLyrTblRec.Color = Color.FromColorIndex(ColorMethod.ByAci, cid);

                        //}
                    }


                    acLyrTblRec.DowngradeOpen();
                    tr.Commit();
                }
            }
            catch (Exception ex)
            {
                new WriteLogs().writeLogs("图层初始化异常：异常原因" + ex.ToString(), "exelog");
            }
        }

        /// <summary>
        /// 初始化文字样式
        /// </summary>
        /// <param name="StyleName">文字样式名称</param>
        /// <param name="FontName">字体名称</param>
        /// <param name="WidthFactor">宽度因子</param>
        /// <param name="charset">字符集，中文3212默认134</param>
        /// <param name="pf">字族，</param>
        public static void InitTextStyle(Database acCurDb, string StyleName, string FontName, double WidthFactor, int charset = 134, int pf = 48)
        {
            try
            {
                new WriteLogs().writeLogs("字体初始化，字体<" + StyleName +":"+ FontName+">", "exelog");
                //Database acCurDb = HostApplicationServices.WorkingDatabase;
                using (Transaction tr = acCurDb.TransactionManager.StartTransaction())
                {
                    TextStyleTable st = tr.GetObject(acCurDb.TextStyleTableId, OpenMode.ForWrite) as TextStyleTable;
                    TextStyleTableRecord acTextStyleTblRec;
                    acTextStyleTblRec = tr.GetObject(acCurDb.Textstyle,
                                                         OpenMode.ForWrite) as TextStyleTableRecord;

                    Teigha.GraphicsInterface.FontDescriptor acFont;
                    acFont = acTextStyleTblRec.Font;

                    #region 字体设置
                    if (!st.Has(StyleName))//字体设置
                    {
                        st.UpgradeOpen();
                        TextStyleTableRecord str = new TextStyleTableRecord()
                        {
                            Name = StyleName,
                            Font = new Teigha.GraphicsInterface.FontDescriptor(FontName, acFont.Bold, acFont.Italic, acFont.CharacterSet, acFont.PitchAndFamily),
                            XScale = WidthFactor,
                            TextSize = 0,

                        };

                        st.Add(str);
                        tr.AddNewlyCreatedDBObject(str, true);
                        st.DowngradeOpen();
                    }
                    else
                    {
                        st.UpgradeOpen();
                        TextStyleTableRecord str = tr.GetObject(st[StyleName], OpenMode.ForWrite) as TextStyleTableRecord;
                        str.Font = new Teigha.GraphicsInterface.FontDescriptor(FontName, acFont.Bold, acFont.Italic, acFont.CharacterSet, acFont.PitchAndFamily);
                        str.XScale = WidthFactor;
                        str.TextSize = 0;
                        st.DowngradeOpen();
                    }

                    #endregion
                    tr.Commit();
                }
            }
            catch (Exception ex)
            {
                new WriteLogs().writeLogs("字体初始化异常：异常原因" + ex.ToString(), "exelog");
            }
        }

        /// <summary>
        /// 初始化文字样式
        /// </summary>
        /// <param name="StyleName">文字样式名称</param>
        /// <param name="FontName">字体名称</param>
        /// <param name="WidthFactor">宽度因子</param>
        /// <param name="charset">字符集，中文3212默认134</param>
        /// <param name="pf">字族，</param>
        public static void InitTextStyle(Database acCurDb, string StyleName, string FontName, string fronFileName, double WidthFactor)
        {
            //Database acCurDb = HostApplicationServices.WorkingDatabase;
            using (Transaction tr = acCurDb.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(acCurDb.TextStyleTableId, OpenMode.ForWrite) as TextStyleTable;
                #region 字体设置
                if (!st.Has(StyleName))//字体设置
                {
                    TextStyleTableRecord str = new TextStyleTableRecord()
                    {
                        Name = StyleName,
                        FileName = fronFileName,
                        XScale = WidthFactor,
                        TextSize = 0,

                    };
                    st.Add(str);
                    tr.AddNewlyCreatedDBObject(str, true);
                }
                else
                {
                    TextStyleTableRecord str = tr.GetObject(st[StyleName], OpenMode.ForWrite) as TextStyleTableRecord;
                    str.FileName = fronFileName;
                    str.XScale = WidthFactor;
                    str.TextSize = 0;
                }

                #endregion
                tr.Commit();
            }
        }

        public static void InitLeaderStyle(Database acCurDb, double scale)
        {
            try
            {
                new WriteLogs().writeLogs("引线样式初始化", "exelog");
                //Database acCurDb = HostApplicationServices.WorkingDatabase;
                using (Transaction tr = acCurDb.TransactionManager.StartTransaction())
                {
                    TextStyleTable st = tr.GetObject(acCurDb.TextStyleTableId, OpenMode.ForWrite) as TextStyleTable;
                    #region 引线
                    string StName = "ML";
                    if (scale < 1)
                    {
                        StName += Math.Round(1 / scale, 0).ToString() + "-1";
                    }
                    else
                    {
                        StName += "1-" + scale.ToString();
                    }
                    DBDictionary mlstyles = (DBDictionary)tr.GetObject(acCurDb.MLeaderStyleDictionaryId, OpenMode.ForRead);
                    MLeaderStyle mldst;
                    if (!mlstyles.Contains(StName))
                    {
                        mldst = new MLeaderStyle();
                        mldst.TextHeight = 2.5;
                        mldst.TextStyleId = st[Extensions.curFont];
                        mldst.ArrowSize = 0;
                        mldst.TextAlignAlwaysLeft = true;
                        //mldst.ExtendLeaderToText = false;

                        mldst.LandingGap = 0;
                        mldst.EnableDogleg = false;
                        mldst.TextAlignmentType = TextAlignmentType.LeftAlignment;
                        mldst.TextAttachmentDirection = TextAttachmentDirection.AttachmentHorizontal;
                        mldst.TextAngleType = TextAngleType.HorizontalAngle;
                        mldst.Scale = scale;
                        mldst.SetTextAttachmentType(TextAttachmentType.AttachmentBottomOfTopLine, LeaderDirectionType.LeftLeader);
                        mldst.SetTextAttachmentType(TextAttachmentType.AttachmentBottomOfTopLine, LeaderDirectionType.RightLeader);
                        ObjectId mLeaderStyle = mldst.PostMLeaderStyleToDb(acCurDb, StName);
                        tr.AddNewlyCreatedDBObject(mldst, true);
                    }

                    #endregion
                    tr.Commit();
                }
            }
            catch (Exception ex)
            {
                new WriteLogs().writeLogs("引线样式初始化异常：异常原因" + ex.ToString(), "exelog");
            }
        }


        /// <summary>
        /// 配置标注样式
        /// </summary>
        /// <param name="plotunit">绘图单位</param>
        /// <param name="paperunit">标注单位</param>
        /// <param name="scale">比例</param>
        /// <param name="tstyle">文字样式</param>
        public static void InitDimStyle(Database db, Unit plotunit, Unit paperunit, double scale, string tstyle)
        {
            try
            {
                //Database db = HostApplicationServices.WorkingDatabase;
                new WriteLogs().writeLogs("标注样式初始化", "exelog");
                Dictionary<Unit, double> UnitDic = new Dictionary<Unit, double>()
            {
                { Unit.Meter,1000 },
                { Unit.Centimeter,10 },
                { Unit.Millimeter,1 },
            };
                Dictionary<Unit, string> UnitDicStr = new Dictionary<Unit, string>()
            {
                { Unit.Meter,"M" },
                { Unit.Centimeter,"CM" },
                { Unit.Millimeter,"MM" },
            };
                double factor = UnitDic[plotunit] / UnitDic[paperunit];


                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    DimStyleTable dst = tr.GetObject(db.DimStyleTableId, OpenMode.ForWrite) as DimStyleTable;
                    TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                    dst.UpgradeOpen();
                    string DimStyleName = string.Format("{0}-{1}-", UnitDicStr[plotunit], UnitDicStr[paperunit]);
                    if (scale < 1)
                    {
                        DimStyleName += Math.Round(1 / scale, 0).ToString() + "-1";
                    }
                    else
                    {
                        DimStyleName += "1-" + scale.ToString();
                    }
                    DimStyleTableRecord dstr = new DimStyleTableRecord();
                    if (!dst.Has(DimStyleName))
                    {

                        dstr.Name = DimStyleName;
                        dstr.Dimscale = scale;
                        dstr.Dimtxsty = st[tstyle];
                        //dstr.Dimclrd = Color.FromColorIndex(ColorMethod.ByAci, 6);
                        //dstr.Dimclre = Color.FromColorIndex(ColorMethod.ByAci, 6);
                        dstr.Dimdli = 5;
                        dstr.Dimsah = true;

                        //dstr.Dimblk = StyleTools.GetArrowObjectId(db,"_NONE");
                        //dstr.Dimblk1 = StyleTools.GetArrowObjectId(db, "_NONE");
                        //dstr.Dimblk2 = StyleTools.GetArrowObjectId(db, "_NONE");

                        //dstr.Dimblk = StyleTools.GetArrowObjectId(db, "_ARCHTICK");
                        //dstr.Dimblk1 = StyleTools.GetArrowObjectId(db, "_ARCHTICK");
                        //dstr.Dimblk2 = StyleTools.GetArrowObjectId(db, "_ARCHTICK");

                        dstr.Dimdle = 2;
                        dstr.Dimexe = 1;
                        dstr.Dimexo = 1;
                        dstr.Dimclrd = Color.FromColorIndex(ColorMethod.ByAci, 4);
                        dstr.Dimclre = Color.FromColorIndex(ColorMethod.ByAci, 4);
                        //dstr.Dimfxlon = true;

                        dstr.DimfxlenOn = true;
                        dstr.Dimfxlen = 4;
                        //dstr.Dimfxlen = 4;
                        dstr.Dimtxt = 2.5;

                        dstr.Dimasz = 1;
                        dstr.Dimatfit = 0;
                        dstr.Dimtix = true;
                        dstr.Dimsoxd = false;
                        dstr.Dimtoh = true;
                        dstr.Dimtmove = 1;
                        //dstr.Dimtad = 1;
                        dstr.Dimgap = 0.6;
                        dstr.Dimdec = 0;
                        dstr.Dimtih = false;
                        dstr.Dimtoh = false;
                        dstr.Dimdsep = '.';
                        dstr.Dimlfac = factor;
                        dstr.Dimtofl = true;
                        dstr.Dimtad = 1;
                        dst.Add(dstr);
                        tr.AddNewlyCreatedDBObject(dstr, true);
                    }
                    else
                    {
                        dstr = tr.GetObject(dst[DimStyleName], OpenMode.ForWrite) as DimStyleTableRecord;
                        dstr.Dimscale = scale;

                        dstr.Dimclrd = Color.FromColorIndex(ColorMethod.ByAci, 4);
                        dstr.Dimclre = Color.FromColorIndex(ColorMethod.ByAci, 4);
                        dstr.Dimdli = 5;
                        dstr.Dimsah = true;
                        //dstr.Dimblk = StyleTools.GetArrowObjectId(db, "_NONE");
                        //dstr.Dimblk1 = StyleTools.GetArrowObjectId(db, "_NONE");
                        //dstr.Dimblk2 = StyleTools.GetArrowObjectId(db, "_NONE");
                        //dstr.Dimblk = StyleTools.GetArrowObjectId(db, "_ARCHTICK");
                        //dstr.Dimblk1 = StyleTools.GetArrowObjectId(db, "_ARCHTICK");
                        //dstr.Dimblk2 = StyleTools.GetArrowObjectId(db, "_ARCHTICK");
                        dstr.Dimdle = 1;//尺寸线   —  超出标记                
                        dstr.Dimexe = 1;//尺寸界线 —  超出尺寸线
                        dstr.Dimexo = 1;//尺寸界线 —  起点偏移量 
                                        //dstr.DimfxlenOn = false;
                                        //dstr.Dimfxlen = 4;

                        dstr.DimfxlenOn = true;
                        dstr.Dimfxlen = 4;
                        dstr.Dimtxt = 2.5;//文字 — 文字高度
                        dstr.Dimasz = 1;//符号和箭头  —  箭头大小
                        dstr.Dimatfit = 0;
                        dstr.Dimtix = true;
                        dstr.Dimsoxd = false;
                        dstr.Dimtoh = true;
                        dstr.Dimtmove = 1;
                        dstr.Dimtad = 1;
                        dstr.Dimgap = 0.6;//文字 — 从尺寸线偏移
                        dstr.Dimdec = 0;
                        dstr.Dimtih = false;
                        dstr.Dimtoh = false;
                        dstr.Dimtofl = true;
                        dstr.Dimdsep = '.';
                        dstr.Dimtxsty = st[tstyle];
                        dstr.Dimlfac = factor;

                    }
                    dst.DowngradeOpen();
                    tr.Commit();
                }
            }
            catch (Exception ex)
            {
                new WriteLogs().writeLogs("标注样式初始化异常：异常原因" + ex.ToString(), "exelog");
            }
        }

        /// <summary>
        /// 初始化文字比例图块
        /// </summary>
        public static void InitBlock(Database acCurDb)
        {
            try
            {
                //Database acCurDb = HostApplicationServices.WorkingDatabase;
                new WriteLogs().writeLogs("标准块初始化", "exelog");
                using (Transaction tr = acCurDb.TransactionManager.StartTransaction())
                {
                    TextStyleTable st = tr.GetObject(acCurDb.TextStyleTableId, OpenMode.ForWrite) as TextStyleTable;

                    #region 自定义块
                    BlockTable bt = (BlockTable)tr.GetObject(acCurDb.BlockTableId, OpenMode.ForRead);
                    BlockTableRecord btr = new BlockTableRecord();
                    if (!bt.Has("BG"))
                    {
                        btr = new BlockTableRecord();
                        btr.Name = "BG";
                        bt.UpgradeOpen();
                        bt.Add(btr);
                        tr.AddNewlyCreatedDBObject(btr, true);
                        Teigha.DatabaseServices.Polyline Paa = new Teigha.DatabaseServices.Polyline();
                        Paa.AddVertexAt(0, new Point2d(0, 0), 0, 0, 0);
                        Paa.AddVertexAt(1, new Point2d(250 / Math.Sqrt(3), 250), 0, 0, 0);
                        Paa.AddVertexAt(2, new Point2d(-250 / Math.Sqrt(3), 250), 0, 0, 0);
                        Paa.Closed = true;
                        btr.AppendEntity(Paa);
                        tr.AddNewlyCreatedDBObject(Paa, true);

                        Line Laa = new Line(new Point3d(-250 / Math.Sqrt(3), 0, 0), new Point3d(1275, 0, 0));
                        btr.AppendEntity(Laa);
                        tr.AddNewlyCreatedDBObject(Laa, true);

                        AttributeDefinition curbg = new AttributeDefinition();
                        curbg.Position = new Point3d(175, 80, 0);
                        curbg.Height = 250;
                        curbg.WidthFactor = st[Extensions.curFont].GetXScale();
                        curbg.Tag = "H标高";
                        curbg.TextStyleId = st[Extensions.curFont];
                        btr.AppendEntity(curbg);
                        tr.AddNewlyCreatedDBObject(curbg, true);
                    }
                    if (!bt.Has("BGMark"))
                    {
                        btr = new BlockTableRecord();
                        btr.Name = "BGMark";
                        bt.UpgradeOpen();
                        bt.Add(btr);
                        tr.AddNewlyCreatedDBObject(btr, true);
                        Teigha.DatabaseServices.Polyline Paa = new Teigha.DatabaseServices.Polyline();
                        Paa.AddVertexAt(0, new Point2d(0, 0), 0, 0, 0);
                        Paa.AddVertexAt(1, new Point2d(350 / Math.Sqrt(3), 250), 0, 0, 0);
                        Paa.AddVertexAt(2, new Point2d(-350 / Math.Sqrt(3), 250), 0, 0, 0);
                        Paa.Closed = true;
                        btr.AppendEntity(Paa);
                        tr.AddNewlyCreatedDBObject(Paa, true);

                        Line Laa = new Line(new Point3d(-350 / Math.Sqrt(3), 0, 0), new Point3d(850, 0, 0));
                        btr.AppendEntity(Laa);
                        tr.AddNewlyCreatedDBObject(Laa, true);

                        AttributeDefinition curbg = new AttributeDefinition();
                        curbg.Position = new Point3d(350, 80, 0);
                        curbg.Height = 350;
                        curbg.WidthFactor = st[Extensions.curFont].GetXScale();
                        curbg.Tag = "H标高";
                        curbg.TextStyleId = st[Extensions.curFont];
                        btr.AppendEntity(curbg);
                        tr.AddNewlyCreatedDBObject(curbg, true);
                    }
                    if (!bt.Has("Mark"))
                    {
                        btr = new BlockTableRecord();
                        btr.Name = "Mark";
                        bt.UpgradeOpen();
                        bt.Add(btr);
                        tr.AddNewlyCreatedDBObject(btr, true);
                        Polyline Paa = new Polyline();
                        Paa.AddVertexAt(0, new Point2d(0, -10), 0, 5, 5);
                        Paa.AddVertexAt(1, new Point2d(0, 450), 0, 5, 5);
                        btr.AppendEntity(Paa);
                        tr.AddNewlyCreatedDBObject(Paa, true);
                        AttributeDefinition curbg = new AttributeDefinition();
                        curbg.Position = new Point3d(60, 50, 0);
                        curbg.Height = 350;
                        curbg.WidthFactor = st[Extensions.curFont].GetXScale();
                        curbg.Tag = "剖切线";
                        curbg.TextStyleId = st[Extensions.curFont];
                        btr.AppendEntity(curbg);
                        tr.AddNewlyCreatedDBObject(curbg, true);
                    }
                    if (!bt.Has("RMark"))
                    {
                        btr = new BlockTableRecord();
                        btr.Name = "RMark";
                        bt.UpgradeOpen();
                        bt.Add(btr);
                        tr.AddNewlyCreatedDBObject(btr, true);
                        Polyline Paa = new Polyline();
                        Paa.AddVertexAt(0, new Point2d(450, -10), 0, 5, 5);
                        Paa.AddVertexAt(1, new Point2d(450, 450), 0, 5, 5);
                        btr.AppendEntity(Paa);
                        tr.AddNewlyCreatedDBObject(Paa, true);
                        AttributeDefinition curbg = new AttributeDefinition();
                        curbg.Position = new Point3d(60, 50, 0);
                        curbg.Height = 350;
                        curbg.WidthFactor = st[Extensions.curFont].GetXScale();
                        curbg.Tag = "剖切线";
                        curbg.TextStyleId = st[Extensions.curFont];
                        btr.AppendEntity(curbg);
                        tr.AddNewlyCreatedDBObject(curbg, true);
                    }
                    if (!bt.Has("LRMarkT"))
                    {
                        btr = new BlockTableRecord();
                        btr.Name = "LRMarkT";
                        bt.UpgradeOpen();
                        bt.Add(btr);
                        tr.AddNewlyCreatedDBObject(btr, true);
                        Polyline Paa = new Polyline();
                        Paa.AddVertexAt(0, new Point2d(0, 450), 0, 10, 10);
                        Paa.AddVertexAt(1, new Point2d(350, 450), 0, 10, 10);
                        btr.AppendEntity(Paa);
                        tr.AddNewlyCreatedDBObject(Paa, true);
                        AttributeDefinition curbg = new AttributeDefinition();
                        curbg.Position = new Point3d(65, 0, 0);
                        curbg.Height = 350;
                        curbg.WidthFactor = st[Extensions.curFont].GetXScale();
                        curbg.Tag = "剖切线";
                        curbg.TextStyleId = st[Extensions.curFont];
                        btr.AppendEntity(curbg);
                        tr.AddNewlyCreatedDBObject(curbg, true);
                    }
                    if (!bt.Has("LRMarkB"))
                    {
                        btr = new BlockTableRecord();
                        btr.Name = "LRMarkB";
                        bt.UpgradeOpen();
                        bt.Add(btr);
                        tr.AddNewlyCreatedDBObject(btr, true);
                        Polyline Paa = new Polyline();
                        Paa.AddVertexAt(0, new Point2d(0, 0), 0, 10, 10);
                        Paa.AddVertexAt(1, new Point2d(350, 0), 0, 10, 10);
                        btr.AppendEntity(Paa);
                        tr.AddNewlyCreatedDBObject(Paa, true);
                        AttributeDefinition curbg = new AttributeDefinition();
                        curbg.Position = new Point3d(100, 40, 0);
                        curbg.Height = 350;
                        curbg.WidthFactor = st[Extensions.curFont].GetXScale();
                        curbg.Tag = "剖切线";
                        curbg.TextStyleId = st[Extensions.curFont];
                        btr.AppendEntity(curbg);
                        tr.AddNewlyCreatedDBObject(curbg, true);
                    }
                    //-------------------------------------------------------------------------------------------
                    if (!bt.Has("RightP"))
                    {
                        BlockTableRecord btr2 = new BlockTableRecord();
                        btr2.Name = "RightP";
                        bt.UpgradeOpen();
                        bt.Add(btr2);
                        tr.AddNewlyCreatedDBObject(btr2, true);

                        Solid Array = new Solid(
                            new Point3d(774.9048 - 974.2305, 49.6974, 0),
                            new Point3d(710.2305 - 974.2305, 0, 0),
                            new Point3d(974.2305 - 974.2305, 0, 0)
                            )
                        { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                        btr2.AppendEntity(Array);
                        tr.AddNewlyCreatedDBObject(Array, true);

                        Line L = new Line(new Point3d(974.2305 - 974.2305, 0, 0),
                            new Point3d(-225.7695 - 974.2305, 0, 0))
                        { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                        btr2.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);

                        AttributeDefinition curzp = new AttributeDefinition();
                        curzp.Position = new Point3d(-160 - 974.2305, 73.1925, 0);
                        curzp.Height = 350;
                        curzp.WidthFactor = st[Extensions.curFont].GetXScale();
                        curzp.Tag = "右剖切线";
                        curzp.TextStyleId = st[Extensions.curFont];
                        btr2.AppendEntity(curzp);
                        tr.AddNewlyCreatedDBObject(curzp, true);
                    }


                    //-------------------------------------------------------------------------------------------
                    if (!bt.Has("LeftP"))
                    {
                        BlockTableRecord btr2 = new BlockTableRecord();
                        btr2.Name = "LeftP";
                        bt.UpgradeOpen();
                        bt.Add(btr2);
                        tr.AddNewlyCreatedDBObject(btr2, true);

                        Solid Array = new Solid(
                            new Point3d(-184.6346, 49.6974, 0),
                            new Point3d(-119.9603, 0, 0),
                            new Point3d(-383.9603, 0, 0)
                            )
                        { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                        btr2.AppendEntity(Array);
                        tr.AddNewlyCreatedDBObject(Array, true);

                        Line L = new Line(new Point3d(-383.9603, 0, 0), new Point3d(816.0397, 0, 0))
                        { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                        btr2.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);

                        AttributeDefinition curzp = new AttributeDefinition();
                        curzp.Position = new Point3d(-160, 73.1925, 0);
                        curzp.Height = 350;
                        curzp.WidthFactor = st[Extensions.curFont].GetXScale();
                        curzp.Tag = "左剖切线";
                        curzp.TextStyleId = st[Extensions.curFont];
                        btr2.AppendEntity(curzp);
                        tr.AddNewlyCreatedDBObject(curzp, true);
                    }
                    //-------------------------------------------------------------------------------------------
                    if (!bt.Has("TopMark"))
                    {
                        BlockTableRecord btr2 = new BlockTableRecord();
                        btr2.Name = "TopMark";
                        bt.UpgradeOpen();
                        bt.Add(btr2);
                        tr.AddNewlyCreatedDBObject(btr2, true);

                        Solid Array = new Solid(
                            new Point3d(774.9048 - 374.2305, 49.6974, 0),
                            new Point3d(710.2305 - 374.2305, 0, 0),
                            new Point3d(974.2305 - 374.2305, 0, 0)
                            )
                        { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                        btr2.AppendEntity(Array);
                        tr.AddNewlyCreatedDBObject(Array, true);
                        Polyline L = new Polyline() { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                        L.AddVertexAt(0, new Point2d(974.2305 - 374.2305, 0), 0, 0, 0);
                        L.AddVertexAt(1, new Point2d(374.2305 - 374.2305, 0), 0, 5, 5);
                        L.AddVertexAt(2, new Point2d(374.2305 - 374.2305, -400), 0, 5, 5);

                        btr2.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);

                        AttributeDefinition curzp = new AttributeDefinition();
                        curzp.Position = new Point3d(474 - 374.2305, -400, 0);
                        curzp.Height = 350;
                        curzp.WidthFactor = st[Extensions.curFont].GetXScale();
                        curzp.Tag = "A";
                        curzp.TextStyleId = st[Extensions.curFont];
                        btr2.AppendEntity(curzp);
                        tr.AddNewlyCreatedDBObject(curzp, true);
                    }


                    //-------------------------------------------------------------------------------------------
                    if (!bt.Has("BottomMark"))
                    {
                        BlockTableRecord btr2 = new BlockTableRecord();
                        btr2.Name = "BottomMark";
                        bt.UpgradeOpen();
                        bt.Add(btr2);
                        tr.AddNewlyCreatedDBObject(btr2, true);

                        Solid Array = new Solid(
                           new Point3d(774.9048 - 374.2305, -49.6974, 0),
                           new Point3d(710.2305 - 374.2305, 0, 0),
                           new Point3d(974.2305 - 374.2305, 0, 0)
                           )
                        { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                        btr2.AppendEntity(Array);
                        tr.AddNewlyCreatedDBObject(Array, true);
                        Polyline L = new Polyline() { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                        L.AddVertexAt(0, new Point2d(974.2305 - 374.2305, 0), 0, 0, 0);
                        L.AddVertexAt(1, new Point2d(374.2305 - 374.2305, 0), 0, 5, 5);
                        L.AddVertexAt(2, new Point2d(374.2305 - 374.2305, 400), 0, 5, 5);

                        btr2.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);

                        AttributeDefinition curzp = new AttributeDefinition();
                        curzp.Position = new Point3d(474 - 374.2305, 73.1925, 0);
                        curzp.Height = 350;
                        curzp.WidthFactor = st[Extensions.curFont].GetXScale();
                        curzp.Tag = "A";
                        curzp.TextStyleId = st[Extensions.curFont];
                        btr2.AppendEntity(curzp);
                        tr.AddNewlyCreatedDBObject(curzp, true);
                    }

                    if (!bt.Has("TTP"))
                    {
                        BlockTableRecord btr2 = new BlockTableRecord();
                        btr2.Name = "TTP";
                        bt.UpgradeOpen();
                        bt.Add(btr2);
                        tr.AddNewlyCreatedDBObject(btr2, true);

                        Solid Array = new Solid(
                            new Point3d(49.6974, 774.9048 - 974.2305, 0),
                            new Point3d(0, 710.2305 - 974.2305, 0),
                            new Point3d(0, 974.2305 - 974.2305, 0)
                            )
                        { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                        btr2.AppendEntity(Array);
                        tr.AddNewlyCreatedDBObject(Array, true);

                        Line L = new Line(new Point3d(0, 974.2305 - 974.2305, 0), new Point3d(0, -225.7695 - 974.2305, 0))
                        { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                        btr2.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);

                        AttributeDefinition curzp = new AttributeDefinition();
                        curzp.Position = new Point3d(373.1925, -60 - 974.2305, 0);
                        curzp.Height = 350;
                        curzp.Rotation = GeTools.DegreeToRadian(90);
                        curzp.WidthFactor = st[Extensions.curFont].GetXScale();
                        curzp.Tag = "上坡";
                        curzp.TextStyleId = st[Extensions.curFont];
                        btr2.AppendEntity(curzp);
                        tr.AddNewlyCreatedDBObject(curzp, true);
                    }

                    if (!bt.Has("LeftMark"))
                    {
                        BlockTableRecord btr2 = new BlockTableRecord();
                        btr2.Name = "LeftMark";
                        bt.UpgradeOpen();
                        bt.Add(btr2);
                        tr.AddNewlyCreatedDBObject(btr2, true);

                        Solid Array = new Solid(
                           new Point3d(-49.6974, -184.6346, 0),
                           new Point3d(0, -119.9603, 0),
                           new Point3d(0, -383.9603, 0)
                           )
                        { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                        btr2.AppendEntity(Array);
                        tr.AddNewlyCreatedDBObject(Array, true);
                        Polyline L = new Polyline() { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                        L.AddVertexAt(0, new Point2d(0, -383.9603), 0, 0, 0);
                        L.AddVertexAt(1, new Point2d(0, -383.9603 + 600), 0, 5, 5);
                        L.AddVertexAt(2, new Point2d(400, -383.9603 + 600), 0, 5, 5);
                        //Line L = new Line(new Point3d(974.2305 - 974.2305, 0, 0), new Point3d(-225.7695 - 974.2305, 0, 0))
                        //{ Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                        btr2.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);

                        AttributeDefinition curzp = new AttributeDefinition();
                        curzp.Position = new Point3d(110, -240, 0);
                        curzp.Height = 350;
                        curzp.WidthFactor = st[Extensions.curFont].GetXScale();
                        curzp.Tag = "B";
                        curzp.TextStyleId = st[Extensions.curFont];
                        btr2.AppendEntity(curzp);
                        tr.AddNewlyCreatedDBObject(curzp, true);
                    }


                    //-------------------------------------------------------------------------------------------
                    if (!bt.Has("RightMark"))
                    {
                        BlockTableRecord btr2 = new BlockTableRecord();
                        btr2.Name = "RightMark";
                        bt.UpgradeOpen();
                        bt.Add(btr2);
                        tr.AddNewlyCreatedDBObject(btr2, true);

                        Solid Array = new Solid(
                            new Point3d(49.6974, -184.6346, 0),
                            new Point3d(0, -119.9603, 0),
                            new Point3d(0, -383.9603, 0)
                            )
                        { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                        btr2.AppendEntity(Array);
                        tr.AddNewlyCreatedDBObject(Array, true);
                        Polyline L = new Polyline() { Color = Color.FromColorIndex(ColorMethod.ByAci, 7), };
                        L.AddVertexAt(0, new Point2d(0, -383.9603), 0, 0, 0);
                        L.AddVertexAt(1, new Point2d(0, -383.9603 + 600), 0, 5, 5);
                        L.AddVertexAt(2, new Point2d(-400, -383.9603 + 600), 0, 5, 5);
                        btr2.AppendEntity(L);
                        tr.AddNewlyCreatedDBObject(L, true);

                        AttributeDefinition curzp = new AttributeDefinition();
                        curzp.Position = new Point3d(-373.1925 + 60, -240, 0);
                        curzp.Height = 350;
                        curzp.WidthFactor = st[Extensions.curFont].GetXScale();
                        curzp.Tag = "B";
                        curzp.TextStyleId = st[Extensions.curFont];
                        btr2.AppendEntity(curzp);
                        tr.AddNewlyCreatedDBObject(curzp, true);
                    }
                    #endregion
                    tr.Commit();
                }
            }
            catch (Exception ex)
            {
                new WriteLogs().writeLogs("标准块初始化异常：异常原因" + ex.ToString(), "exelog");
            }
        }

        #endregion
    }
}
